<template>
	<view :style="{height:shh+'px'}"></view>
	<scroll-view class="list-wrap" scroll-y @scroll="scrollListener">
		<!-- 虚拟列表所有项的高度 完成就到详情-->
		<view class="scroll-bar" :style="{height:bheight}"></view>
		<!-- 虚拟列表项 -->
		<view class="list" :style="{top:top}">
			<uni-list :border="true">
				<template v-for="(val,index) in showList" :key="index">
					<uni-list-chat  :title="val.name" :avatar-list="val.avatarlist" :note="val.times"
						:time="val.times" badge-positon="left">
						
						<view  class="chat-custom-right">
							<text  @click="addfink(val)" v-if="val.iscount==1" class="chat-custom-text bg1aad19 colorfff size24 pg10-25">接受</text>
							<text v-else class="chat-custom-text bgc2c2c2 colorfff size24 pg10-25">已添加</text>
						</view>
						
					</uni-list-chat>
				</template>
			</uni-list>
		</view>


	</scroll-view>

</template>

<script>
	export default {
		data() {
			return {
				inputvalue: "",
				wheight: "",
				bheight: "",
				top: "",
				list: [], // 超长的显示数据
				itemHeight: 67, // 每一列的高度
				showNum: 15, // 显示几条数据
				start: 0, // 滚动过程显示的开始索引
				end: 10, // 滚动过程显示的结束索引
				avatarList: [{
					url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png'
				}],
			}
			vkkk: ''

		},
		onLoad() {
			
			// this.http.setcid({
			// 	id:'7ee9da20a5c2033d351dc720df622c369b57a50ff54b14b9e414c31958270bd0',
			// 	cid:uni.getStorageSync('getui_cid')
			// })
			
			
			
			

			this.list = uni.getStorageSync('adduser')

			for (let i = this.list.length - 1; i >= 0; i--) {
				this.list[i].istabbar = 0
				this.list[i].avatarlist = [{
					url: this.list[i].avatar
				}]
				this.list[i].times = new Date(this.list[i].time).toLocaleString()

				if (new Date().getTime() - this.list[i].time > 259200000) {

					this.list.splice(i, 1);
				}
			}
			uni.setStorageSync('adduser', this.list)

		},
		computed: {
			showList() {
				return this.list.slice(this.start, this.end);
			}
		},
		mounted() {

			this.wheight = this.itemHeight * this.showNum + 'px';
			this.bheight = this.itemHeight * this.list.length + 'px';

		},
		methods: {
			addfink(item){
				console.log(item)
				
				if (uni.getStorageSync('friend')) {
				
					var fares = uni.getStorageSync('friend')
					fares.unshift(item)
					uni.setStorageSync('friend', fares)
				
				} else {
					uni.setStorageSync('friend', [item])
				}
				
				
				// this.http.addfriend(item).then(res=>{
				// 	item.iscount=0
				// 	console.log(res,"斤斤计较")
				// })
			},
			sousou(e) {
				this.inputvalue = e.detail.value

			},
			scrollListener(e) {
				let scrollTop = e.detail.scrollTop
				this.start = Math.floor(scrollTop / this.itemHeight);
				this.end = this.start + this.showNum;
				this.top = this.start * this.itemHeight + 'px';
			}
		}
	}
</script>

<style lang="scss">
	.list {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		list-style: none;
	}

	.list-wrap {
		height: calc(100vh - 50px);
	}
</style>